$(document).ready(function() {
    // remove Search Value  -------------------------------- *
	$('.search input[type=text]').focus(function(){
				if($(this).val() == 'Search...' ){
					$(this).val('');
				}	
			});
	$('.search input[type=text]').blur(function(){
				if($(this).val() == '' ){
					$(this).val('Search...');
				}
			});
   /* *********************************************
	* Sliders 
	* *********************************************/	
	
	// mainSlider  -------------------------------- *
	$('.main-flexslider').flexslider({
		animation: "slide",
		directionNav: false,
		slideshow: true,
		slideshowSpeed: 5000,
		animationSpeed: 900,
		start: function(slider){
			// $('body').removeClass('loading');
		}
	});
	// sideSlider  -------------------------------- *
	$('.side-slider').flexslider({
		animation: "fade",
		controlNav: false, 
		slideshow: true,
		prevText: "",
		nextText: "",
		slideshowSpeed: 6000,
		start: function(slider){
			//$('body').removeClass('loading');
		}
	});
	// clubsSlider  -------------------------------- *
	$('.clubs-slider').flexslider({
		animation: "fade",
		controlNav: false,
		directionNav: false, 
		slideshow: true,
		slideshowSpeed: 6000,
		animationSpeed: 1000,
		start: function(slider){
			//$('body').removeClass('loading');
		}
	});
	
	// gallery  -------------------------------- *
	$('#carousel').flexslider({
        animation: "slide",
        controlNav: false,
        animationLoop: false,
        slideshow: false,
        itemWidth: 56,
        itemMargin: 5,
		prevText: "",  
		nextText: "",
        asNavFor: '#slider'
      });
      
      $('#slider').flexslider({
        animation: "fade",
        slideshow: true,
		controlNav: false,
		slideshowSpeed: 4000,
		animationLoop: true,
		pausePlay: true,
		pauseText: '',
		playText: '',
		prevText: "",         
		nextText: "",
		
        sync: "#carousel",
		start: function(slider){
    	$('span.index').text(slider.count);
   	 	$('span.index').text(slider.currentSlide);
    	$('span.index').text(function(i,txt) { return parseInt(txt, 10) + 1; } );

  },
  after: function(slider) {
    $('span.index').text(slider.currentSlide);
    $('span.index').text(function(i,txt) { return parseInt(txt, 10) + 1; });

  }
  
        
      });
	  var total = $('#carousel .flex-viewport li').length;
	  $('span.total').text(' / ' + total);
	  
	  
	  
	  /******************************************
	  *  fancyBox
	  ******************************************/
	  $('.fancybox').fancybox();
	
	// news ticker  -------------------------------- *
	function tick(){
		$('#ticker li:first').slideUp( function () { $(this).appendTo($('#ticker')).slideDown(); });
	}
	setInterval(function(){ tick () }, 5000);
	
	// accordion -------------------------------- *
			/*jQuery('.side-menu h4').click(function(){
				jQuery('.side-menu ul').each(function(index, element) {
                    jQuery(this).slideUp();
					
                });
				
				if((jQuery(this).children('.side-menu ul').css('display') == 'none')) {
					jQuery(this).children('.side-menu ul').slideToggle();
				}
			});*/
	
	// appends  -------------------------------- *
	$( ".quick-menu li a" ).append( "<span class='icon'></span>" );
	$( ".club-name" ).append( "<span class='arrow'></span>" );
	$( ".side-menu h4 ul li" ).append( "<span class='arrow'>&#155;</span>" );
	$( ".bullet-list li" ).append( $( "<span class='bullet'></span>" ) );
	$( ".to-top, .back-btn" ).append( $( "<span class='icon'></span>" ) );
	$( ".club-categories li .category-details a.more" ).append( $( "<span class='icon'></span>" ) );
	$( ".calendar-right-side .calendar-help" ).prepend( $( "<span class='icon'></span>" ) );
	$('.sitemap li li').prepend( $( "<span class='icon'></span>" ) );
	$('.sitemap li li li').prepend( $( "<span class='icon'></span>" ) );
	$('.not_found li').prepend( $( "<span class='icon'></span>" ) );
	$( ".bullet-list li" ).wrapInner( "<span class='list-text'></span>" );
	$( ".to-top, .back-btn" ).wrapInner( "<span class='button-text'></span>" );
	$('.bullet-list > li > span > span.bullet, .to-top > span > span.icon, .back-btn > span > span.icon').each(function() {
		$(this).parent().before(this);
	});
	
	
	// style adjustments  -------------------------------- *
	$('table.main tr:even td').css('background', '#f2f2f2');
	
	$( ".dotted-block:first" ).css('padding-top', '0');
	
	$( ".dotted-block  .image-block:even img" ).css({'float': 'right', 'margin-left': '27px'}); 
	$( ".dotted-block  .image-block:odd img" ).css({'float': 'left', 'margin-right': '27px'});
	// $( ".dotted-block  .image-block:odd .text" ).css({'float': 'right'});
	// $( ".dotted-block  .image-block:even .text" ).css({'float': 'left'});
	$( ".center-column p:last-child" ).css({'margin-bottom': '40px'});
	$( ".dotted-block:last-child" ).css({'border-bottom': '0px'});
	height = $('.inner-wrapper').height();
	$('.inner-side-panel').css('height', height-170);
	
	// to top   -------------------------------- *
	$('.to-top').click(function(){
		$('html, body').animate({
			scrollTop: $(".inner-content h2").offset().top
		}, 700);
	});
	
	/* subString 
	----------------------------------------------*/
	$('.side-slider p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 170));
	});
	
	
	$('.club-categories li .category-details p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 200));
	});
	
	
	$('.news-list li p, .search-list li p').each(function() {
		var $this = $(this);
		$this.text( $this.text().slice(0, 280));
	});
	
	
	// ------------------------------------------------------
	// image width
	
	
	$('.bullet-list').parent('.text').css('float', 'left');
	
	
});
$(window).load(function() {
	$('.text-block').each(function(){
		var textBlock = $(this).width();
		var textBlockImage = $(this).children('.image-block').children('img').width()+ 29;
		var textBlockText = (textBlock - textBlockImage);
		$(this).children('.image-block').children('.text').width(textBlockText);
			
	});
});

$(window).load(function() {
		// top 
        $('.news-block:even p').each(function(index, element) {
            if ( $(this).children('i').length > 0 ) {
				$(this).children('i').css({float: 'right', marginRight: '0', marginLeft: '24px'});
				
		}
		else{
			$(this).children('span').css('width', 'auto');
		}
        });
		
		// bottom 
		$('.news-block:odd p').each(function(index, element) {
			if ( $(this).children('i').length > 0 ) {
				
				$(this).children('span').css({width: '435px'});
		}
		else{
			
			//$('.news-block:odd h4').css({float: 'left', width: 'auto'});
			$(this).children('span').css({width: 'auto'});
		}
		});
		
		$('.news-block p').each(function(){
			var y = $(this).width();
			var x = $(this).children('i').children('img').width()+26;
			$(this).children('.news-block p i + span').width(y-x);
			$(this).children('i').width($(this).children('i').children('img').width()+2);
			
			// console.log("image width" +'\n' + x);
			
			// console.log("paragraph" +'\n' + y);
		});
		
		$('.list-fake span.square').html('&#9642;');
    });
	
	
	// table strips 

    $('.center-table tr:odd td').css('background', '#f2f2f2');